Repository navigation
Conversation
|
@fametrano Thank you for your proposal. Can you summarize the PR description more concisely in your own words, please. |
|
@jonatack fair request, in my own words: BIP375's text says to sort the silent payment codes lexicographically to assign k; instead, its validator and its vectors assign k by output index. This PR changes the text to match the vectors, #2207 changes the vectors to match the text; either removes the contradiction. I prefer index order because it needs no definition of how a "code" is encoded and compared, and the outputs cannot be reordered once the scripts are set anyway (L185). To reproduce in a minute, apply this to @@ -317,11 +317,13 @@
scan_key_k_values = {}
# Validate each SP output
- for output_idx, output_map in enumerate(psbt.o):
- if PSBT_OUT_SP_V0_INFO not in output_map:
- continue # Skip non-SP outputs
-
- sp_info = output_map[PSBT_OUT_SP_V0_INFO]
+ sp_outputs = [
+ (output_map[PSBT_OUT_SP_V0_INFO], output_idx, output_map)
+ for output_idx, output_map in enumerate(psbt.o)
+ if PSBT_OUT_SP_V0_INFO in output_map
+ ]
+ sp_outputs.sort(key=lambda entry: (entry[0], entry[1]))
+ for sp_info, output_idx, output_map in sp_outputs:
scan_pubkey_bytes = sp_info[:33]
spend_pubkey_bytes = sp_info[33:]Today, at master The PR also rewords two vector descriptions that no longer said what they test once the text is index order ("not sorted lexicographically by spend key" names a rule the text no longer states): both are reworded, in the file and in the BIP's table, and the validator's counter comment now says which order it follows. No vector bytes change. On #2207. If the owners prefer this direction, #2207's sort and its ordering-driven vector regeneration become unnecessary, but its other half, the labeled spend key in |
|
@fametrano #2207 was opened to match the vectors and validation with the BIP text. |
|
@macgyver13 right, #2207 and this PR fix the same contradiction in opposite directions: #2207 edits the vectors and validator to match the prose (lexicographic), this PR edits the prose to match the vectors and validator (output-index order). Measured against master (09e2103): the validator as published assigns k by output index and passes all 42 vectors. Applying #2207's lexicographic sort instead gives 41/42 — the "two sp outputs, output 0 label=3 / output 1 label=1" vector, published as valid, no longer produces its own PSBT_OUT_SCRIPTs, because its two spend keys are in descending order. So the vectors and the reference validator already agree on index order; only the prose dissents. That's why I proposed changing the sentence rather than the vectors. If the editors prefer #2207's direction, that vector's expected scripts have to change too. Happy to go whichever way they decide. |
|
Thanks for your input @macgyver13. @fametrano: I think it’s up to the owners of the BIP rather than the Editors whether they want to adjust the text of the BIP or the implementation. |
e4ba7f8 to
261678a
Compare
|
Thanks @macgyver13 — good catch. The stray |
50344e1 to
60ec6f2
Compare
941dd74 to
136dae3
Compare
71818fb to
4e7ffa3
Compare
|
Rebased onto master after #2286, merged by jonatack (only conflict was the changelog, now 0.1.3). @andrewtoth @achow101 @josibake, this and #2207 still need your call on which way to fix the k ordering. |
|
Perhaps the best path here might be a mix of the two pulls:
Edit: I see a similar suggestion in #2256 (comment): "the labeled spend key in PSBT_OUT_SP_V0_INFO, is independent and still needed: I would suggest reducing #2207 to that half rather than closing it, and I am glad to help rebase it on this." Yes, agree. |
The reference validator and the test vectors assign k per scan key in output index order, but the text said lexicographic order. Change the text to match them. For a labeled address, PSBT_OUT_SP_V0_INFO holds the labeled spend key, but the test vectors held the base spend key. Fix the vectors and say so in the field definition. This fix is by macgyver13, from bitcoin#2207. Add vectors that tell the two orders apart. Co-authored-by: macgyver13 <4712150+macgyver13@users.noreply.github.com>
4e7ffa3 to
7519f2a
Compare
|
Thanks @jonatack, done: this now has the ordering rule from here and the |
|
The BIP-375 test vectors that assign @jvgelder was the first to point out that the vectors didn't match the text, while implementing Caravan. That's why I opened #2207. Implementations that follow the text as written:
All of them sort by the 33-byte spend key in @fametrano, are you aware of any other implementations besides btclib that assign |
|
#2316 fixes the P2WPKH programs and signatures in |
|
@macgyver13, thanks for the clear account. No, I'm not aware of any other. btclib followed the vectors, and it will follow whichever ordering the BIP settles on. That said, the BIP is still a Draft, and I don't think early implementations should settle this decision. |
BIP-375 says to assign k in lexicographic order of the silent payment codes, but its reference validator and test vectors assign it in output index order. This changes the text to match them.
It also includes @macgyver13's fix from #2207: for a labeled address,
PSBT_OUT_SP_V0_INFOholds the labeled spend key, and the test vectors now do too. Two valid vectors and one invalid vector fail under lexicographic order, so the ordering rule is tested. #2207 and this PR now differ only in the ordering rule.Found while implementing BIP-375 in btclib: btclib-org/btclib#768
Made with my usual tools: a computer, the Internet and an LLM. The mistakes, as usual, are all mine.